<template>
	<view class="padding">
		<view class="bg-yellow">
			<view class="padding">
				<view>科爱豆</view>
				<view class="tx">
					<text class="text-xsl text-bold" v-if="kaCoin<100000">{{kaCoin}}</text>
					<text class="text-xsl text-bold" v-else>{{kaCoin/10000}}万</text>
					<text @tap='goRecharge' class="margin-left cu-btn line-white round">充值</text>
				</view>
			</view>
			<view class="iconfont icon-data"></view>
		</view>
		<view class="cu-list padding bg-white margin-top">
			<view class="flex margin-top" :key='i.id' v-for="i in coinList">
				<view class="margin-bottom">
					<view class="text-lg text-bold">{{coinFromArr[i.coinFrom-1]}}</view>
					<view class="text-gray text-df margin-top">
						{{i.createTime}}
					</view>
				</view>
				<view v-if="i.coinChange>=0" class="text-red text-xxl text-bold">
					+{{i.coinChange}}
				</view>
				<view v-else class="text-green text-xxl text-bold">
					{{i.coinChange}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {coinDetail} from '@/api/api.js'
	export default {
		data() {
			return {
				kaCoin:0,
				coinList:[],
				coinFromArr:['充值','赠送','消费','退还']
			};
		},
		onLoad(e) {
			if(e.kaCoin){
				this.kaCoin = e.kaCoin
			}
			this.getCoinDetail();
			uni.$on('setKaCoin',(data)=>{
				this.kaCoin=data.kaCoin;
				this.getCoinDetail();
			})
		},
		methods:{
			goRecharge(){
				uni.navigateTo({
					url:"../recharge/recharge?kaCoin="+this.kaCoin
				})
			},
			getCoinDetail(){
				coinDetail().then(res=>{
					if(res.code==200){
						this.coinList = res.data;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cu-list{
		.flex{
			justify-content: space-between;
			align-items: center;
			border-bottom:solid 1rpx $u-border-color;
		}
	}
	.bg-yellow{
		position: relative;
		border-radius: 16rpx;
		&>view:last-child{
			position: absolute;
			font-size: 150rpx;
			color: rgba(255,255,255,0.5);
			top: 45%;
			right: 0rpx;
			transform: rotate(40deg);
			transform-origin: 100% 0%;
		}
		.tx{
			height: 120rpx;
			display: flex;
			align-items: center;
		}
	}
</style>
